package com.vm.osm.business.controller;

import com.vm.osm.business.common.ControllerExceptionHandler;
import com.vm.osm.business.common.ErrCode;
import com.vm.osm.business.common.exception.BusinessException;
import com.vm.osm.business.dto.omp.type_dicts.TypeDict;
import com.vm.osm.business.dto.req.ReqUpdateEquType;
import com.vm.osm.business.dto.req.evaluate.ReqEvaluate;
import com.vm.osm.business.dto.rsp.RspEquTypePage;
import com.vm.osm.business.dto.rsp.evaluate.StarInfo;
import com.vm.osm.business.entity.EamEquType;
import com.vm.osm.business.service.IEvaluateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by chenzui on 2018/2/5.
 */
@RestController
@RequestMapping("/v1.0")
@Api(value = "EvaluateController",description = "工单评价",tags = {"EvaluateController"})
public class EvaluateController extends ControllerExceptionHandler {
    private Logger LOG = Logger.getLogger(this.getClass());

    @Value("${omp_api_url}")
    private String OMP_API_URL;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private IEvaluateService evaluateService;
    /**
     * 评价信息初始化
     * @return
     */
    @ApiOperation(value = "评价信息初始化",notes = "评价信息初始化")
    @RequestMapping(value = "/dict/init",method = RequestMethod.GET)
    public Object getInitData(){
        LOG.info("评价信息初始化");
        String URL = OMP_API_URL + "/omp/v1.0/type_dicts/6/get_tops";
        return restTemplate.getForEntity(URL, Object.class).getBody();
    }

    /**
     * 工单评价
     * @param
     * @return
     */
    @ApiOperation(value = "工单评价",notes = "工单评价")
    @ApiImplicitParam(name = "reqEvaluate",value = "工单评价参数",required = true,dataType = "ReqEvaluate")
    @RequestMapping(value = "/order/evaluate",method = RequestMethod.PUT)
    public void updateEquTypes(@RequestBody ReqEvaluate reqEvaluate, HttpServletRequest request){
        LOG.info("工单评价");

        evaluateService.evaluate(reqEvaluate,request);
    }

}
